using System.IO;
using System.Xml.Serialization;
using CommonLibrary.Models;

namespace CommonLibrary.Extensions
{
    public static class XmlFileParser<T> where T : XmlConfigFile , new()
    {
        public static T ParseXmlFile(string pathToFile)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            FileStream fileStream = new FileStream(pathToFile, FileMode.Open);
            T configFile = (T) serializer.Deserialize(fileStream);
            
            fileStream.Close();
            fileStream.Dispose();

            return configFile;
        }
    }
}